#pragma once

#ifndef modelSoft_H
#define modelSoft_H

#include <QtWidgets/QMainWindow>
#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Pln.hxx>
#include <gp_Lin2d.hxx>
#include <vtkSmartPointer.h>
#include <vtkNew.h>
#include <vtkIdFilter.h>
#include <vtkDataSetSurfaceFilter.h>
#include "ui_modelSoft.h"
#include <IVtkTools_ShapePicker.hxx>
#include "QIVtkSelectionPipeline.h"
#include "viewWidget.cpp"
#include <OccGeoSelector.h>
#include "OccVertexSelector.h"
#include "OccFaceSelector.h"
#include "OccEdgeSelector.h"
#include "OccShapeSelector.h"
#include "RWTools.h"
#include "CubeFeature.h"
#include <ConeFeature.h>
#include <CylinderFeature.h>
#include <SphereFeature.h>
#include <TorusFeature.h>
#include <baseFeature.h>
#include <historyMananger.h>
#include <brepFeature.h>
#include <historyMananger.h>
#include <expressionWidget.h>
#include <storeManager.h>
#include "SARibbon.h"

class modelSoft : public SARibbonMainWindow
{
    Q_OBJECT

public:
    modelSoft(QWidget* parent = nullptr);

    Handle(QIVtkSelectionPipeline) updateCubePipelineShape(Handle(QIVtkSelectionPipeline) pipeline, CubeFeature* cubeFeature);
    Handle(QIVtkSelectionPipeline) updateConePipelineShape(Handle(QIVtkSelectionPipeline) pipeline, ConeFeature* coneFeature);
    Handle(QIVtkSelectionPipeline) updateCylinderPipelineShape(Handle(QIVtkSelectionPipeline) pipeline, CylinderFeature* cylinderFeature);
    Handle(QIVtkSelectionPipeline) updateSpherePipelineShape(Handle(QIVtkSelectionPipeline) pipeline, SphereFeature* sphereFeature);
    Handle(QIVtkSelectionPipeline) updateTorusPipelineShape(Handle(QIVtkSelectionPipeline) pipeline, TorusFeature* torusFeature);

    //! make box test.
    Handle(QIVtkSelectionPipeline) makeBox(CubeFeature* cubeFeature);

    //! make cone test.
    Handle(QIVtkSelectionPipeline) makeCone(ConeFeature* coneFeature);

    //! make sphere test.
    Handle(QIVtkSelectionPipeline) makeSphere(SphereFeature* sphereFeature);

    //! make cylinder test.
    Handle(QIVtkSelectionPipeline) makeCylinder(CylinderFeature* cylinderFeature);

    //! make torus test.
    Handle(QIVtkSelectionPipeline) makeTorus(TorusFeature* torusFeature);

    void RemovePipelineFromRendererById(Standard_Integer id);

    Handle(QIVtkSelectionPipeline) makeLine(const gp_Pnt& pos1 = gp_Pnt(0.0, 0.0, 0.0), const gp_Pnt& pos2 = gp_Pnt(1.0, 1.0, 1.0));

    void RemovePipelineFromRenderer(Handle(QIVtkSelectionPipeline) pipeline);

    Handle(QIVtkSelectionPipeline) CreatePipeline(const TopoDS_Shape& shape, Standard_Integer shapeId, bool specifyId);

    Handle(QIVtkSelectionPipeline) CreatePipelineByFeature(BaseFeature* feature);

    void BrepOperation(TopoDS_Shape& resultShape, const TopoDS_Shape& shape1, const TopoDS_Shape& shape2, int op);

    void RemoveSelectedActor(Handle(QIVtkSelectionPipeline) delSelPipe);
    //几何变换Occ对象
    Handle(QIVtkSelectionPipeline) TransformActor(Handle(QIVtkSelectionPipeline) actor, const gp_Trsf& transform, int resultId);
    //创建局部坐标系
    void createCoordinate();

    void changeSelector(IVtk_SelectionMode mode);
    //点选择器显示选择点
    vtkSmartPointer<vtkActor> CreateTempSphereActor(float radius, const gp_Pnt& position);

    ~modelSoft();

protected:
    //创建所有action 链接信号和槽
    void createActions();

    //创建菜单
    void createMenus();


private slots:

    //create boxWindow
    void onClickBoxButton();

    //create ConeWindow
    void onClickConeButton();

    //create CylinderWindow
    void onClickCylinderButton();

    //create SphereWindow
    void onClickSphereButton();

    //create TorusWindow
    void onClickTorusButton();

    //create LineWindow
    void onClickCircleButton();

    //PickMode
    void onClickCancelPickButton();

    void OnClickPickLineButton();

    void OnClickPickVertexButton();

    void OnClickPickFaceButton();

    void OnClickPickShapeButton();

    void OnClickBrepButton();

    void OnClickTransformButton();

    void OnClickStretchButton();

    void OnClickRevolButton();

    void OnClickFilletButton();

    void OnClickHollowButton();

    void OnClickCurveButton();

    void reSet();
    //投影
    void viewPerspective();
    void viewParallel();
    //定向视图
    //1:front 2:back 3:right 4:left 5:top 6:bottom
    void switchViewOrientation(int orientation);
    void frontView() {
        switchViewOrientation(1);
    }
    void topView() {
        switchViewOrientation(5);
    }
    void rightView() {
        switchViewOrientation(3);
    }
    void backView() {
        switchViewOrientation(2);
    }
    void leftView() {
        switchViewOrientation(4);
    }
    void bottomView() {
        switchViewOrientation(6);
    }


    void onUndo();
    void onRedo();
    void onExpression();

    //保存读取操作
    void onClickSaveToFile();
    void onClickOpenFile();
    void onClickNewFile();

public:
    viewWidget* myView = new viewWidget();
    expressionWidget* m_expressionWidget;
    //PipelineMap
    std::map<Standard_Integer, Handle(QIVtkSelectionPipeline)> m_pipelineMap;
    //选择器
    OccGeoSelector* currSelector;
    OccGeoSelector* currVertexSelector = new OccVertexSelector();
    OccGeoSelector* currShapeSelector = new OccShapeSelector();
    OccGeoSelector* currEdgeSelector = new OccEdgeSelector();
    OccGeoSelector* currFaceSelector = new OccFaceSelector();
    Standard_Integer shapeTag = 1;
    //!feature map用于保存创建Shape的特征
    std::map<Standard_Integer, BaseFeature*> m_Features;
    Ui::modelSoftClass* ui;
    historyMananger* m_historyManager;
    storeManager* m_storeManager;

};
#endif //modelSoft_H
